<template>
	<div>
		<el-dialog :title="title" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible">
			<el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading"
				:class="method==='view'?'readonly':''" :disabled="method==='view'" label-width="120px">
				<el-row :gutter="15">
					<el-col :span="12">
						<el-form-item label="类型" prop="type" :rules="[
                  {required: true, message:'类型不能为空', trigger:'blur'}
                 ]">
							<el-select v-model="inputForm.type" placeholder="请选择" style="width: 100%;">
								<el-option v-for="item in $dictUtils.getDictList('zhaohang')" :key="item.value"
									:label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="12">
            <el-form-item label="归属公司" prop="company.id"
                :rules="[
                  {required: true, message:'归属公司不能为空', trigger:'blur'}
                 ]">
          <SelectTree
                      ref="company"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.company.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.company.id=value}"/>
           </el-form-item>
        </el-col> -->
					<el-col :span="12">
						<el-form-item label="结算户" prop="accnbr" :rules="[
                  {required: true, message:'结算户不能为空', trigger:'blur'}
                 ]">
							<el-input v-model="inputForm.accnbr" placeholder="请填写结算户"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="分行号" prop="bbknrb" :rules="[
                  {required: true, message:'分行号不能为空', trigger:'blur'}
                 ]">
							<el-select v-model="inputForm.bbknrb" placeholder="请选择" style="width: 100%;">
								<el-option v-for="item in $dictUtils.getDictList('zhaohang_branch')" :key="item.value"
									:label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="用户id" prop="uid" :rules="[
                  {required: true, message:'用户id不能为空', trigger:'blur'}
                 ]">
							<el-input v-model="inputForm.uid" placeholder="请填写用户id"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="AES" prop="aeskey" :rules="[
                  {required: true, message:'AES不能为空', trigger:'blur'}
                 ]">
							<el-input v-model="inputForm.aeskey" placeholder="请填写AES"></el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="银行公钥" prop="pubkey" :rules="[
                  {required: true, message:'银行公钥不能为空', trigger:'blur'}
                 ]">
							<el-input type="textarea" v-model="inputForm.pubkey" placeholder="请填写银行公钥"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="私钥" prop="prikey" :rules="[
                  {required: true, message:'私钥不能为空', trigger:'blur'}
                 ]">
							<el-input type="textarea" v-model="inputForm.prikey" placeholder="请填写私钥"></el-input>
						</el-form-item>
					</el-col>
<!-- v-if="inputForm.type=='0'||inputForm.type=='1'" -->
					<el-col :span="12" >
						<el-form-item label="招行标识" prop="identification" :rules="[]">
							<el-input v-model="inputForm.identification" placeholder="请填写招行标识"></el-input>
						</el-form-item>
					</el-col>
					<!-- v-if="inputForm.type=='0'||inputForm.type=='1'" -->
					<el-col :span="12" >
						<el-form-item label="平台私钥" prop="platprivatekey" :rules="[]">
							<el-input type="textarea" v-model="inputForm.platprivatekey" placeholder="请填写平台私钥">
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="备注信息" prop="remarks" :rules="[
					   ]">
							<el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button size="small" @click="visible = false">关闭</el-button>
				<el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定
				</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import SelectTree from '@/components/treeSelect/treeSelect.vue'
	export default {
		data() {
			return {
				title: '',
				method: '',
				visible: false,
				loading: false,
				inputForm: {
					id: '',
					type: '',
					// company: {
					//   id: ''
					// },
					accnbr: '',
					bbknrb: '',
					uid: '',
					aeskey: '',
					pubkey: '',
					prikey: '',
					identification: '',
					platprivatekey: '',
					remarks: ''
				}
			}
		},
		components: {
			SelectTree
		},
		methods: {
			init(method, id) {
				this.method = method
				this.inputForm.id = id
				if (method === 'add') {
					this.title = `新建招行配置`
				} else if (method === 'edit') {
					this.title = '修改招行配置'
				} else if (method === 'view') {
					this.title = '查看招行配置'
				}
				this.visible = true
				this.loading = false
				this.$nextTick(() => {
					this.$refs.inputForm.resetFields()
					if (method === 'edit' || method === 'view') { // 修改或者查看
						this.loading = true
						this.$http({
							url: `/zhaohang/zhaohangconfig/zhaoHangConfig/queryById?id=${this.inputForm.id}`,
							method: 'get'
						}).then(({
							data
						}) => {
							this.inputForm = this.recover(this.inputForm, data.zhaoHangConfig)
							this.loading = false
						})
					}
				})
			},
			// 表单提交
			doSubmit() {
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						this.loading = true
						this.$http({
							url: `/zhaohang/zhaohangconfig/zhaoHangConfig/save`,
							method: 'post',
							data: {
								'company': this.$store.state.user.companyId,
								...this.inputForm
							}
						}).then(({
							data
						}) => {
							this.loading = false
							if (data && data.success) {
								this.visible = false
								this.$message.success(data.msg)
								this.$emit('refreshDataList')
							}
						})
					}
				})
			}
		}
	}
</script>
